# -*- coding: utf-8 -*-
#===================================================
# @Time : 2021/3/11 14:45                           
# @Author : weni09                                  
# @File : setting.py
#===================================================
import os,sys

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

# print(BASE_DIR)

# JWT 配置项
from datetime import timedelta
SECRET_KEY = 'jijiojf32131adfaf&*^&fa90ir203-roq0-fai31oijo@#'
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_TIME = timedelta(days=1)
REFRESH_TOKEN_EXPIRE_TIME = timedelta(days=2)

#国际化开关，时区设置
USE_TZ = False
TIME_ZONE='Asia/Shanghai'

#Database setting
import urllib.parse
MYSQL_HOST = os.getenv('MYSQL_HOST','www.weni09.top')
MYSQL_PORT = os.getenv('MYSQL_PORT',1633)
MYSQL_USERNAME = os.getenv('MYSQL_USERNAME','root')
MYSQL_PASSWORD = urllib.parse.quote_plus(os.getenv('MYSQL_PASSWORD','www.weni09.top'))
MYSQL_DBNAME = os.getenv('MYSQL_DBNAME','blog')


PG_USERNAME = os.getenv('PG_USERNAME','postgres')
PG_PASSWORD = urllib.parse.quote_plus(os.getenv('PG_PASSWORD','Weni!520@119#'))
PG_HOST = os.getenv('PG_HOST','www.weni09.top')
PG_PORT = os.getenv('PG_PORT',15432)
PG_DBNAME = os.getenv('PG_DBNAME','blog')
# ADMIN_MYSQL_DBNAME = os.getenv('MYSQL_DBNAME','fastapi-admin')
MYSQL_URL = f'mysql://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DBNAME}?minsize=1&maxsize=100'
# ADMIN_MYSQL_URL = f'mysql://{MYSQL_USERNAME}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{ADMIN_MYSQL_DBNAME}?minsize=1&maxsize=100'
POSTGRES_URL = f'postgres://{PG_USERNAME}:{PG_PASSWORD}@{PG_HOST}:{PG_PORT}/{PG_DBNAME}?minsize=1&maxsize=100'

TORTOISE_ORM = {
    "connections": {"default":POSTGRES_URL},
    "apps": {
        "blog": {
            "models": ['aerich.models','blog.models','admin.models'],
            "default_connection": "default",
        },
    },
    "use_tz": USE_TZ,
}

#Redis
# redis://:root12345@172.16.137.129:6379/0?encoding=utf-8
REDIS_HOST= os.getenv('REDIS_HOST','www.weni09.top')
REDIS_PORT= os.getenv('REDIS_PORT','16973')
REDIS_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/0?encoding=utf-8"

#Salt
SALT_KEY = 'Testhfudahfau392309jdsafk!29u92,.!hjinkdsafrirjewfefmFjeaNGJJISDfa'

#blog setting
DEFAULT_SUMMARY = '请填写文章摘要......'



#上传文件对象名
UPLOAD_FILE_NAME = ('avatar','image')

###文件存放路径
STATIC_PATH = 'file'
#图片存放路径
IMAGE_PATH = os.path.join(STATIC_PATH,'images')
#图片上传大小限制
IMAGE_SIZE = 1 * 1024 * 1024
#图片上传数量限制
IMAGE_COUNT = 5

#头像存放路径
AVATAR_PATH = os.path.join(STATIC_PATH,'avatar')
#头像上传大小限制
AVATAR_SIZE = 500 * 1024


#跨域设置
#域名
CORS_ORIGINS = [
     "*"
    # "https://localhost",
    # "http://localhost",
    # "http://localhost:8000",
    # "http://localhost:8081/"
]

